import { defineStore } from 'pinia'
import { GET_RECORDS,SET_RECORD,REMOVE_RECORDS } from '@/utils/searchHistory'
// 本地历史搜索记录
const useSearchHistoryStore = defineStore('SearchHistory', {
  state: () => {
    return {
      history: JSON.parse(GET_RECORDS()) || []
    }
  },
  actions: {
    // 添加历史记录
    append(word){
      this.history.push(word)
      SET_RECORD(JSON.stringify(this.history))
    },
    // 清空历史记录
    clear(){
      this.history=[]
      REMOVE_RECORDS()
    }
  },
  getters: {

  }
});
export default useSearchHistoryStore;